<template>
<div class="save-wrapper ui container" v-if="show">
  <div class="ui very relaxed  grid">
    <div class="sixteen wide column">

      <form action="" v-if="vo" class="ui form" @submit.prevent="submit_confirm">
        <div class="ui header">{{titleType}}模型</div>

        <div class="field">
          <label for="">名称</label>
          <input type="text" v-model="vo.title" name="title" placeholder="请输入标题">
        </div>
        <div class="field">
          <label for="">标识</label>
          <input type="text" v-model="vo.name" name="name" placeholder="请输入标识">
        </div>
        <myenum :param="{}" v-if="enumField_pre.fval!==undefined" :field="enumField_pre" @setVo='setEnum' ></myenum>
        <enum_many v-if="enumField_btns.fval!==undefined" :field="enumField_btns" @setVo='setEnum' ></enum_many>
        <myenum :param="{}" v-if="enumField.fval!==undefined" :field="enumField" @setVo='setEnum' ></myenum>
        <myenum :param="{}" v-if="enumField_can_del.fval!==undefined" :field="enumField_can_del" @setVo='setEnum' ></myenum>
        <myenum :param="{}" v-if="enumField_is_modal_edit.fval!==undefined" :field="enumField_is_modal_edit" @setVo='setEnum' ></myenum>
          <myenum :param="{}" v-if="is_modal_edit&&enumField_insert_hide.fval!==undefined" :field="enumField_insert_hide" @setVo='setEnum' ></myenum>
          <myenum :param="{}" v-if="is_modal_edit&&enumField_ok_jump.fval!==undefined" :field="enumField_ok_jump" @setVo='setEnum' ></myenum>

        <div v-if="model_data" class="fluid field">
          <label for="">在什么模型里使用</label>
          <fselect fname="use_in" @selectValsChange='selectEvent' :val="vo.use_in" :data="model_data" placeholder="请选择在什么模型里使用"></fselect>
        </div>

        <div class="field" v-if="isUpdate">
          <label for="">Tab</label>
          <attr_aroup v-if="vo.id" :mid="vo.id"></attr_aroup>
        </div>

        <div class="field" v-if="isUpdate">
          <label for="">字段组</label>
          <attr_zip v-if="vo.id" :mid="vo.id"></attr_zip>
        </div>

        <div class="field" v-if="isUpdate">
          <label for="">搜索字段</label>
          <attr_search v-if="vo.id" :mid="vo.id"></attr_search>
        </div>
        <div class="field">
          <label for="">列表定义</label>
          <textarea name="list" v-model="vo.list"></textarea>
        </div>
        <div class="field">
          <label for="">操作字段配置</label>
          <textarea name="opBtns" v-model="vo.opBtns"></textarea>
        </div>
        <div class="field">
          <label for="">字段验证</label>
          <textarea name="validList" v-model="vo.validList"></textarea>
        </div>
        <div class="field">
          <label for="">搜索配置</label>
          <textarea name="searchConf" v-model="vo.searchConf"></textarea>
        </div>
        <div class="field">
          <label for="">日期查询类型</label>
          <textarea name="date_type" v-model="vo.date_type"></textarea>
        </div>
        <div class="field">
          <label for="">排序字段配置</label>
          <textarea name="sortConf" v-model="vo.sortConf"></textarea>
        </div>
        <div class="field">
          <label for="">字段颜色配置</label>
          <textarea name="colorConf" v-model="vo.colorConf"></textarea>
        </div>
        <div class="field">
          <label for="">字段显示配置</label>
          <textarea name="show_conf" v-model="vo.show_conf"></textarea>
        </div>
        <div class="field">
          <label for="">字段类型配置</label>
          <textarea name="field_type_conf" v-model="vo.field_type_conf"></textarea>
        </div>
        <div class="field">
          <label for="">字段值关联配置</label>
          <textarea name="field_rel_conf" v-model="vo.field_rel_conf"></textarea>
        </div>
        <!--<div class="field">-->
          <!--<label for="">模型绑定配置</label>-->
          <!--&lt;!&ndash;<textarea name="bind_conf" v-model="vo.bind_conf"></textarea>&ndash;&gt;-->
            <!--<input type="text" v-model="vo.bind_conf" name="bind_conf" placeholder="请输入模型绑定配置">-->
        <!--</div>-->


        <myenum :param="{}" v-if="enumField_isStep.fval!==undefined" :field="enumField_isStep" @setVo='setEnum' ></myenum>


        <p class="submitRow">
            <button type="submit" :class="{loading:loadingBtn}" class="ui button">提 交</button>
        </p>
      </form>


    </div>
  </div>
</div>
</template>
<script>
import fselect from 'components/form/select'
import attr_aroup from 'components/edit/attr_aroup'
import attr_search from 'components/edit/attr_search'
import attr_zip from 'components/edit/attr_zip'
import myenum from 'components/field/enum';
import enum_many from 'components/field/enum_many';

import tool from 'src/util/tool';
import util from '_util/index';
import logic from '_logic';



export default {
  data() {
    return {
      enumField:{
        name:'isApi',
        title:'是否走服务数据',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_is_modal_edit:{
        name:'is_modal_edit',
        title:'新增，编辑页面是否是弹出层',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_can_del:{
        name:'can_del',
        title:'是否可以删除',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_isStep:{
        name:'isStep',
        title:'是否使用下一步',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_insert_hide:{
        name:'insert_hide',
        title:'弹出层添加后是否关闭',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_ok_jump:{
        name:'ok_jump',
        title:'成功后是否跳转',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_pre:{
        name:'urlpre',
        title:'Api模块',
        enum_val:[
          {
            id:'user',
            title:'user'
          },
          {
            id:'index',
            title:'index'
          },
          {
            id:'yewu',
            title:'yewu'
          },
        ]
      },
      enumField_btns:{
        name:'btns',
        title:'列表按钮(多选)',
        enum_val:[
          {
            id:'add',
            title:'添加'
          },
          {
            id:'search',
            title:'搜索'
          },
          {
            id:'export',
            title:'导出'
          },
          {
            id:'onOff',
            title:'上下线、删除'
          },
          {
            id:'delete',
            title:'删除'
          },
          {
            id:'timeSearch',
            title:'日期搜索'
          },
        ]
      },
      result: '',
      type: 'add',
      model: {},
      model_data: null,
      pidinfo: {
        title: '父级',
        name: 'pid'
      },
      pdata: {},
      tabs: [],
      fields: {},
      result_type: 'rs_error',
      curIndex: '1',
      vo: null,
        loadingBtn: false,
      show: true
    }
  },
  methods: {
    selectEvent(val,fname) {
      this.vo[fname]=val
    },
    get_model_data() {
      let param = {
        notParse: 1
      }
      util.data.get(this,'Model', param,(rs)=> {
        this.model_data = rs
      });
    },
    setEnum(name, val) {
      this.vo[name]= val;
    },
    submit_confirm() {
      util.showConfirm(this, () => {
        this.onSubmit()
      },{content:'确认提交吗？'});
    },
    onSubmit() {
      let op = this.$store.state.global.op || 'insert';
      let url = tool.getApi(this,'Model', op);
      logic.edit.setSaveLoading(this);

      util.http.SR(this, url, this.vo, '操作成功', (rs) => {
          this.loadingBtn = false;
        util.eventEmit(this, 'afterAdd');
      });

    },
  },
  computed: {
    titleType() {
      return logic.edit.get_titleType(this);
    },
    isUpdate() {
      return this.$store.state.global.op == 'update'
    },
      is_modal_edit() {
        return this.vo.is_modal_edit;
    },
    ctl() {
      return this.$route.query.ctl;
    },

  },
  components: {
    fselect,
    attr_aroup,
    attr_search,
    attr_zip,
    enum_many,
    myenum
  },
  props: ['leftMenu', 'isAdd'],
  created() {
    this.get_model_data();
    this.vo=util.store.get(this, 'editVo')
    this.enumField.fval=this.vo['isApi']||0
    this.enumField_isStep.fval=this.vo['isStep']||0
    this.enumField_insert_hide.fval=this.isAdd?1:this.vo['insert_hide']
    this.enumField_ok_jump.fval=this.isAdd?1:this.vo['ok_jump']
    this.enumField_can_del.fval=this.vo['can_del']||0
    this.enumField_is_modal_edit.fval=this.vo['is_modal_edit']||0
    this.enumField_pre.fval=this.vo['urlpre']||'index'
    this.enumField_btns.fval=this.vo['btns']||JSON.stringify([{code:'search',title:'搜索'}])
  }
}
</script>
<style rel="stylesheet/less" scoped lang="less">@import "../../common/style/mixin";
@dir: "edit/";
form {
    .submitBtn();
}
</style>
